#include<REG51.H>

void delay_ms(unsigned int ms)
{
    unsigned int i, j;
    while (ms--)
    {
        for(i = 0; i < 2; i++){
            for(j = 0; j < 122; j++);
        }
    }
}

void EXINT0() interrupt 0
{
    unsigned char i, j, port;
    EX0 = 0;
    delay_ms(20);
    EX0 = 1;
    P2 = 0xff;
    for (j = 0; j < 8; j++)
    {
        P2 <<= 1;
        port = 0xfe;
        for (i = 1; i < 8; i++)
        {
            P1 = port;
            delay_ms(50);
            port = (port<<1|0x01);
        }
    }
    P2 = 0xff;
    P1 = 0xff;
}

void EXINT1() interrupt 2
{
    unsigned char i;
    EX1 = 0;
    delay_ms(20);
    EX1 = 1;
    for (i = 0; i < 3; i++)
    {
        P1 = 0xff;
        delay_ms(100);
        P1 = 0x00;
        delay_ms(100);
    }
    P1 = 0xff;
    delay_ms(100);
}

void main()
{
    unsigned char p;
    EA = 1;
    IP = 0x04;
    EX0 = 1;
    IT0 = 1;
    EX1 = 1;
    IT1 = 1;
    P1 = p = 0xfe;
    delay_ms(500);
    while(1){
        p = (p<<1 | p>>7);
        P1 = p;
        delay_ms(500);
    }
}